using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BusinessLayer;

public partial class inventory_updateItem : System.Web.UI.Page
{
    BL_UPC UPC = new BL_UPC();
    upcNameSpace.structLookupEAN result;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["upc"] != null)
            {
                edtUPC.Text = Request.QueryString["upc"].ToString();
                edtUPC.ReadOnly = true;
                result = UPC.RetrieveUPC(Request.QueryString["upc"].ToString());
                lblDescription.Text = lblDescription.Text + result.description;
                lblMessage.Text = lblMessage.Text + result.message;
                lblSize.Text = lblSize.Text + result.size;
            }
            else
            {

            }
            ddlType.DataSource = UPC.PopulateItemGroup();
            ddlType.DataTextField = "type";
            ddlType.DataValueField = "type_idx";
            ddlType.DataBind();
        }
    }
    protected void btnSaveExit_Click(object sender, EventArgs e)
    {
        string FullTags = "";
        
        if (tbTag1.Text.Length > 0)
        {
            UPC.AddTag(tbTag1.Text);
            UPC.AttachTag(tbTag1.Text, edtUPC.Text);
        }

        if (tbTag2.Text.Length > 0)
        {
            UPC.AddTag(tbTag2.Text);
            UPC.AttachTag(tbTag2.Text, edtUPC.Text);
        }

        if (tbTag3.Text.Length > 0)
        {
            UPC.AddTag(tbTag3.Text);
            UPC.AttachTag(tbTag3.Text, edtUPC.Text);
        }

        if (tbTag4.Text.Length > 0)
        {
            UPC.AddTag(tbTag4.Text);
            UPC.AttachTag(tbTag4.Text, edtUPC.Text);
        }

        if (tbTag5.Text.Length > 0)
        {
            UPC.AddTag(tbTag5.Text);
            UPC.AttachTag(tbTag5.Text, edtUPC.Text);
        }

        if (tbTag6.Text.Length > 0)
        {
            UPC.AddTag(tbTag6.Text);
            UPC.AttachTag(tbTag6.Text, edtUPC.Text);
        }

        if (tbThreshhold.Text.Length < 1)
        {
            tbThreshhold.Text = "1";
        }

        if (cbNeccessity.Checked)
        {
            int threshhold = 0;
            if ((tbThreshhold.Text.Length < 1) || (Convert.ToInt32(tbThreshhold.Text) < 0))
            {
                threshhold = 1;
            }
            else
            {
                threshhold = Convert.ToInt32(tbThreshhold.Text);
            }
            UPC.addNecessity(edtUPC.Text, threshhold);
        }
      
        UPC.UpdateUPC(edtUPC.Text, 0, Convert.ToInt32(ddlType.SelectedValue),Convert.ToDateTime("01/01/1900"),Convert.ToDouble(EdtPrice.Text));
        Response.Write("<script>window.close();</script>");
    }
}
